Name :
Example4 : Pivot Points

Variables : name,type,value
pivotmethod,Integer,0

Description :
This example computes the "Pivot Points" on the full history.
It works on intraday charts, several days must be displayed.

Remark : This indicator is generally displayed on the price chart. To do so, please go the the "Price Properties" window.
Click on the wrench icon located on the left of the price chart then click on the "Add" button.


Formula :
IF barindex = 0 THEN
	
	initialization = 2 // we are in the middle of a day
	
ELSE
	
	IF dayofweek[1] <> dayofweek THEN
		
		prevmax = newmax
		prevmin = newmin
		prevclose = newclose
		
		newmax = high
		newmin = low
		newopen = open
		newclose = close
		
		initialization = max(0, initialization - 1)
		// initialization = 1 means we are on the first full day
		// initialization = 0 means we are at least on the second day
		
	ELSE
		
		newmax = MAX(newmax, high)
		newmin = MIN(newmin, low)
		newclose = close
		
		// only after initializations
		IF initialization = 0 THEN
			IF pivotmethod = 0 THEN
				pivot = (prevmax + prevmin + prevclose) / 3
			ELSIF pivotmethod = 1 THEN
				pivot = (prevmax + prevmin + prevclose + newopen) / 4
			ELSE
				pivot = (prevmax + prevmin + newopen) / 3
			ENDIF
			
			line0 =  pivot + prevmax - prevmin
			line1 = (2 * pivot) - prevmin
			line2 = pivot
			line3 = (2 * pivot) - prevmax
			line4 = pivot - (prevmax - prevmin)
		ENDIF
		
	ENDIF
	
ENDIF

return line0, line1, line2, line3, line4







